Imports TaxonNamesInterface
Imports System.Runtime.Serialization

<DataContract()> _
Public Class BrNames
    Implements TaxonNamesInterface.INames

    Public Delegate Sub StatusDelegate(ByVal percComplete As Integer, ByVal msg As String)

    Public Shared StatusCallback As StatusDelegate
    Public Shared Cancel As Boolean = False

    Private Shared _namesInt As NamesDataAccess.INamesData

    Private Shared Function NamesInterface() As NamesDataAccess.INamesData
        If _namesInt Is Nothing Then _namesInt = New MySqlNamesDb.TaxonNamesData
        Return _namesInt
    End Function

    Public Sub DeleteNameAuthors(ByVal nameId As Guid) Implements INames.DeleteNameAuthors
        Try
            NamesInterface.DeleteNameAuthors(nameId)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to delete authors")
        End Try
    End Sub

    Public Sub DeleteNameRecord(ByVal nameLsid As String, ByVal newNameLsid As String, ByVal user As String) Implements INames.DeleteName
        Try
            NamesInterface.DeleteNameRecord(nameLsid, newNameLsid, user)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to delete name")
        End Try
    End Sub

    Public Function GetName(ByVal nameId As Guid) As TaxonNamesInterface.Name Implements INames.GetName
        Try
            Return NamesInterface.GetName(nameId)
        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get name")
        End Try
    End Function

    Public Function GetNameAuthors(ByVal nameId As Guid) As List(Of TaxonNamesInterface.NameAuthor) Implements INames.GetNameAuthors
        Try
            Return NamesInterface.GetNameAuthors(nameId)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get authors")
        End Try
    End Function

    Public Function GetNameChildren(ByVal nameId As Guid) As List(Of TaxonNamesInterface.Name) Implements INames.GetNameChildren
        Try
            Return NamesInterface.GetNameChildren(nameId)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get children")
        End Try
    End Function

    Public Function GetNameLSIDs(ByVal pageNumber As Integer, ByVal pageSize As Integer) As List(Of String) Implements INames.GetNameLSIDs
        Try
            Return NamesInterface.GetNameLSIDs(pageNumber, pageSize)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get names")
        End Try
    End Function

    Public Function GetNameSynonyms(ByVal nameId As Guid) As List(Of TaxonNamesInterface.Name) Implements INames.GetNameSynonyms
        Try
            Return NamesInterface.GetNameSynonyms(nameId)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get names")
        End Try
    End Function

    Public Sub InsertUpdateFieldStatus(ByVal recordId As String, ByVal fieldStatusId As Integer, ByVal statusLevelFk As Integer, ByVal user As String) Implements INames.InsertUpdateFieldStatus
        Try
            NamesInterface.InsertUpdateFieldStatus(recordId, fieldStatusId, statusLevelFk, user)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to update field status")
        End Try
    End Sub

    Public Sub InsertUpdateName(ByVal newName As TaxonNamesInterface.Name, ByVal user As String) Implements INames.InsertUpdateName
        Try
            NamesInterface.InsertUpdateName(newName, user)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to update name")
        End Try
    End Sub

    Public Function InsertUpdateNameAuthor(ByVal nameAuthorId As Integer, ByVal nameId As Guid, ByVal basAuthors As String, ByVal combAuthors As String, ByVal basExAuth As String, ByVal combExAuth As String, ByVal isCorrected As Boolean, ByVal user As String) As TaxonNamesInterface.NameAuthor Implements INames.InsertUpdateNameAuthor
        Try
            Return NamesInterface.InsertUpdateNameAuthor(nameAuthorId, nameId, basAuthors, combAuthors, basExAuth, combExAuth, isCorrected, user)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to update author")
        End Try
    End Function

    Public Function ListNameRecords(ByVal searchText As String, ByVal anywhereInText As Boolean) As List(Of TaxonNamesInterface.Name) Implements INames.ListNameRecords
        Try
            Return NamesInterface.SearchNames(searchText, anywhereInText)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to search names")
        End Try
    End Function

    Public Sub DeleteConceptRelationship(ByVal ConceptRelLSID As String, ByVal NewConceptRelLSID As String, ByVal user As String) Implements INames.DeleteConceptRelationship
        Try
            NamesInterface.DeleteConceptRelationship(ConceptRelLSID, NewConceptRelLSID, user)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to delete relationship")
        End Try
    End Sub

    Public Function GetConcept(ByVal conceptId As Guid) As TaxonNamesInterface.Concept Implements INames.GetConcept
        Try
            Return NamesInterface.GetConcept(conceptId)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get concept")
        End Try
    End Function

    Public Function GetConceptRelationship(ByVal ConceptRelId As Guid) As TaxonNamesInterface.ConceptRelationship Implements INames.GetConceptRelationship
        Try
            Return NamesInterface.GetConceptRelationship(ConceptRelId)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get relationship")
        End Try
    End Function

    Public Function GetNameConceptRelationshipRecords(ByVal nameId As Guid, ByVal includeToConcepts As Boolean) As List(Of TaxonNamesInterface.ConceptRelationship) Implements INames.GetNameConceptRelationships
        Try
            Return NamesInterface.GetNameConceptRelationshipRecords(nameId, includeToConcepts)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get relationships")
        End Try
    End Function

    Public Function GetNameConcepts(ByVal nameId As Guid) As List(Of TaxonNamesInterface.Concept) Implements INames.GetNameConcepts
        Try
            Return NamesInterface.GetNameConcepts(nameId)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get concepts")
        End Try
    End Function

    Public Function GetRelationshipTypes() As System.Collections.Generic.List(Of TaxonNamesInterface.RelationshipType) Implements INames.GetRelationshipTypes
        Try
            Return NamesInterface.GetRelationshipTypes()

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get relationship types")
        End Try
    End Function

    Public Sub UpdateConcept(ByVal conc As TaxonNamesInterface.Concept, ByVal user As String) Implements INames.UpdateConcept
        Try
            NamesInterface.UpdateConcept(conc, user)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to update concept")
        End Try
    End Sub

    Public Sub UpdateConceptRelationship(ByVal cr As TaxonNamesInterface.ConceptRelationship, ByVal user As String) Implements INames.UpdateConceptRelationship
        Try
            NamesInterface.UpdateConceptRelationship(cr, user)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to update relationship")
        End Try
    End Sub

    Public Function GetImportTypes() As List(Of TaxonNamesInterface.ImportType) Implements INames.GetImportTypes
        Try
            Return Nothing 'todo ImportData.GetImportTypes()

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get import types")
        End Try
    End Function

    Public Function InsertUpdateImport(ByVal imp As TaxonNamesInterface.Import, ByVal user As String) As Boolean Implements INames.InsertUpdateImport
        Try
            'todo ImportData.InsertUpdateImport(imp, user)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to update import")
        End Try
    End Function

    Public Function GetRanks() As List(Of TaxonNamesInterface.Rank) Implements INames.GetRanks
        Try
            Return NamesInterface.GetRanks()

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get ranks")
        End Try
    End Function

    Public Function RankById(ByVal id As Guid) As TaxonNamesInterface.Rank Implements INames.RankById
        Try
            Return NamesInterface.RankById(id)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get rank")
        End Try
    End Function

    Public Function RankByName(ByVal name As String) As TaxonNamesInterface.Rank Implements INames.RankByName
        Try
            Return NamesInterface.RankByName(name)

        Catch ex As Exception
            Throw New ServiceModel.FaultException("Failed to get rank")
        End Try
    End Function
End Class
